package com.ushine.web.component.design.strategy;

import com.ushine.web.component.design.chain.salary.StaffEnum;
import com.ushine.web.component.design.chain.salary.model.SalaryCalculateBO;
import com.ushine.web.component.design.strategy.context.SalaryContext;
import com.ushine.web.component.design.strategy.strategy.impl.LeaveStaffStrategy;
import com.ushine.web.component.design.strategy.strategy.impl.LeaveTraineeStrategy;
import com.ushine.web.component.design.strategy.strategy.impl.NormalStaffStrategy;
import com.ushine.web.component.design.strategy.strategy.impl.NormalTraineeStrategy;
import com.ushine.web.component.exception.ServiceException;
import com.ushine.web.component.exception.ServiceExceptionEnum;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @Author: yls
 * @Date: 2022/03/04 15:04
 * @Description: 薪资提供调用
 * @Version 1.0
 */
@Component
public class SalaryStrategyClient {
    @Resource
    private LeaveTraineeStrategy leaveTraineeStrategy;

    @Resource
    private LeaveStaffStrategy leaveStaffStrategy;

    @Resource
    private NormalStaffStrategy normalStaffStrategy;

    @Resource
    private NormalTraineeStrategy normalTraineeStrategy;

    /**
     * 功能描述:
     * 〈 客户端、提供给其他service层调用 〉
     *
     * @param salaryCalculate 薪资计算想关的数据
     * @return : void
     * @author : yls
     * @date : 2022/3/9 14:53
     * @throws ServiceException 服务端自定义异常
     */
    public void getSalaryCalculateByType(SalaryCalculateBO salaryCalculate) throws ServiceException {
        SalaryContext salaryContext = new SalaryContext();
        // 获取员工类型
        StaffEnum staffEnum = salaryCalculate.getStaffEnum();
        if (StaffEnum.LEAVE_TRAINEE.equals(staffEnum)) {
            salaryContext.setAbstractSalaryStrategy(leaveTraineeStrategy);
        } else if (StaffEnum.LEAVE_STAFF.equals(staffEnum)) {
            salaryContext.setAbstractSalaryStrategy(leaveStaffStrategy);
        } else if (StaffEnum.NORMAL_TRAINEE.equals(staffEnum)) {
            salaryContext.setAbstractSalaryStrategy(normalTraineeStrategy);
        } else if (StaffEnum.NORMAL_STAFF.equals(staffEnum)) {
            salaryContext.setAbstractSalaryStrategy(normalStaffStrategy);
        } else {
            throw new ServiceException(ServiceExceptionEnum.SALARY_CALCULATE_NOT_SUPPORT_TYPE);
        }
        salaryContext.getSalaryCalculate(salaryCalculate);
    }
}
